﻿using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Contracts.Entities;
using Client.Properties;

namespace Client.Commands
{
    public class PlayMovieCommand : BaseCommand
    {
        public override bool CanExecute(object parameter)
        {
            return parameter as MovieItem != null;
        }

        public override void Execute(object parameter)
        {
            var process = new Process();
            var item = parameter as MovieItem;

            if (String.IsNullOrEmpty(item.FolderPath))
                return;

            foreach (var path in Directory.GetFiles(item.FolderPath))
            {
                if (!Settings.Default.movieFilenameExtensions.Split(',').Any(m => path.EndsWith(m)))
                    return;

                process.EnableRaisingEvents = false;
                process.StartInfo.FileName = path;
                process.Start();
            }
        }
    }
}
